<?php 
class MeberController extends Controller{
	private $dbs;
	private $path;
	public function __construct($datas){
		$this->dbs = $datas;
		$this->path = './datas.php';
	}
	//首页
	public function index(){
		include './tpl/index.html';
	}
	//注册
	public function reg(){
		if(IS_POST){
			$this->dbs[] = array(
			'user' => $_POST['user'],
			'password' => md5($_POST['password'])
			);
			data_to_file($this->dbs, $this->path);
			
			$user = $_POST['user'];
			$password = md5($_POST['password']);
			
			foreach($this->dbs as $v){
				
				if($user == $v['user'] && $password == $v['password']){
					$_SESSION['user'] =$v['user'];
					echo $v['user'];
				$this->success('注册成功','./index.php');	
				}
				
			}
		}
		include './tpl/reg.html';
	}
	//登录
	public function login(){
		if(IS_POST){
			$user = $_POST['user'];
			$password = md5($_POST['password']);
			foreach($this->dbs as $v){
				if($user == $v['user'] && $password == $v['password']){
					$_SESSION['user'] =$v['user'];
				$this->success('登录成功','./index.php');	
				}else{
					$this->error('用户或密码错误');
				}
				
			}
		}
		include './tpl/login.html';
	}
	public function out(){
		session_unset();
		session_destroy();
		$this->success('注销成功','./index.php');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}












?>